﻿@using Orchard.Lists.ViewModels;
@using Orchard.ContentManagement;
@{
	var sourceContainerId = (int)Model.SourceContainerId;
	var targetContainerId = (int)Model.TargetContainerId;
	
    Layout.Title = T("Choose Items");

    var targetContainers = ((IEnumerable<ContentItem>)Model.Containers).Select(
        contentItem => new SelectListItem {
            Text = T("Move to {0}", contentItem.ContentManager.GetItemMetadata(contentItem).DisplayText ?? contentItem.ContentType).ToString(),
            Value = contentItem.Id.ToString(System.Globalization.CultureInfo.InvariantCulture),
			Selected = contentItem.Id == targetContainerId
        }).ToList();

    var sourceContainers = ((IEnumerable<ContentItem>)Model.Containers).Select(
        contentItem => new SelectListItem {
            Text = contentItem.ContentManager.GetItemMetadata(contentItem).DisplayText ?? contentItem.ContentType,
            Value = contentItem.Id.ToString(System.Globalization.CultureInfo.InvariantCulture),
			Selected = contentItem.Id == sourceContainerId
        }).ToList();
	sourceContainers.Insert(0, new SelectListItem { Text = T("No list").ToString(), Value = "" });
}

@using (Html.BeginFormAntiForgeryPost()) {
    <fieldset class="bulk-actions">
        <label for="filterResults">@T("Show")</label>
        <select id="filterResults" name="SelectedFilter">
            @Html.SelectOption((string)Model.SelectedFilter, "", T("any (show all)").ToString())
            @foreach(var filterOption in Model.FilterOptions) {
                @Html.SelectOption((string)Model.SelectedFilter, (string)filterOption.Key, (string)filterOption.Value)
            }
        </select>

        <label for="SourceContainerId">@T("from")</label>
		@Html.DropDownList("SourceContainerId", sourceContainers, new { id = "SourceContainerId" })

        <label for="orderResults" class="bulk-order">@T("Ordered by")</label>
        <select id="orderResults" name="OrderBy">
            @Html.SelectOption((ContentsOrder)Model.OrderBy, ContentsOrder.Created, T("recently created").ToString())
            @Html.SelectOption((ContentsOrder)Model.OrderBy, ContentsOrder.Modified, T("recently modified").ToString())
            @Html.SelectOption((ContentsOrder)Model.OrderBy, ContentsOrder.Published, T("recently published").ToString())
        </select>

        <button type="submit" name="submit.Filter" value="yes">@T("Apply")</button>
    </fieldset>

	<div class="manage">
		@Html.DropDownList("TargetContainerId", targetContainers)
        <button type="submit" name="submit.MoveTo" value="yes">@T("Apply")</button>
	</div>

    
	if ((int)Model.ContentItems.Items.Count == 0) {
		<div class="message info">@T("There are no content items.")</div>
	}
	else {
    <fieldset class="contentItems bulk-items">
		@Display(Model.ContentItems)
     </fieldset>
	}

@Display(Model.Pager)
}